﻿//using System;
//using System.Collections.Generic;
//using System.Text;

using log4net.Core;
using log4net.Appender;
using BizTalkAppender.ESBExceptionHandling;

namespace BizTalkAppender
{
    public class Appender : AppenderSkeleton
    {

        protected override void Append(LoggingEvent loggingEvent)
        {

            ESBExceptionHandling.FaultMessage theMessage = new FaultMessage();
            theMessage.ExceptionObject.InnerExceptionMessage = loggingEvent.ExceptionObject.InnerException.Message;
            theMessage.ExceptionObject.Message = loggingEvent.ExceptionObject.Message;
            theMessage.ExceptionObject.Source = loggingEvent.LoggerName;
            theMessage.ExceptionObject.StackTrace = loggingEvent.LocationInformation.ToString();
            theMessage.ExceptionObject.Type = loggingEvent.Level.DisplayName;
            theMessage.ExceptionObject.TargetSite = loggingEvent.Repository.Name;

            ESBExceptionHandling.BizTalkServiceInstance theInstance = new BizTalkServiceInstance();
            theInstance.UseDefaultCredentials = true;
            theInstance.SubmitFault(theMessage);

            theInstance = null;
            theMessage = null;

        }
    }
}
